﻿
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region FactoryPrice Model -(by fangyifeng at 2013/12/23 18:42:00)

	/// <summary>
	/// FactoryPrice object'FactoryPrice'.
	/// </summary>
    [Serializable]
	public class FactoryPrice : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected decimal _price;
		protected string _factoryModelID;
		protected Factory _factory;
		protected ItemBarCode _itemBarCode;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public FactoryPrice() { }

		public FactoryPrice( decimal price, string factoryModelID, Factory factory, ItemBarCode itemBarCode )
		{
			this._price = price;
			this._factoryModelID = factoryModelID;
			this._factory = factory;
			this._itemBarCode = itemBarCode;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual decimal Price
		{
			get { return _price; }
			set { _price = value; }
		}

		public virtual string FactoryModelID
		{
			get { return _factoryModelID; }
			set
			{
				if ( value != null && value.Length > 30)
					throw new ArgumentOutOfRangeException("Invalid value for FactoryModelID", value, value.ToString());
				_factoryModelID = value;
			}
		}

		public virtual Factory Factory
		{
			get { return _factory; }
			set { _factory = value; }
		}

		
		public virtual ItemBarCode ItemBarCode
		{
			get { return _itemBarCode; }
			set { _itemBarCode = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is FactoryPrice))
				throw new InvalidCastException("This object is not of type FactoryPrice");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((FactoryPrice)obj).Id);
					break;
				case "Price":
					relativeValue = this.Price.CompareTo(((FactoryPrice)obj).Price);
					break;
				case "FactoryModelID":
					relativeValue = this.FactoryModelID.CompareTo(((FactoryPrice)obj).FactoryModelID);
					break;
                default:
                    goto case "Id";
			}
            if (FactoryPrice.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
